﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using MiniStock.Entities.Common.Events;

namespace MiniStock.BusinessLogic.EventDispatcher.MessageMap
{
    public class MessageMapRepositoryEntry
    {
        public Guid Id { get; set; }
        public Guid CorrelationId { get; set; }
        public DateTime Timestamp { get; set; }

        public bool IsMessage { get; set; }
        public string XmlPayload { get; set; }

        [NotMapped]
        public EventBase Message
        {
            get
            {
                if (IsMessage)
                    return XmlPayload.ToEventBase();
                else
                    return null;
            }

            set { 
                IsMessage = true;
                XmlPayload = value.ToXmlString();
            }
        }

        [NotMapped]
        public MessageMap Snapshot
        {
            get
            {
                if (IsMessage)
                    return null;
                else
                    return XmlPayload.ToMessageMap();
            }

            set
            {
                IsMessage = false;
                XmlPayload = value.ToXmlString();
            }
        }

    }
}
